//
//  MineView.m
//  MyProject
//
//  Created by dllo on 15/10/31.
//  Copyright (c) 2015年 蓝鸥0825. All rights reserved.
//

#import "MineView.h"
#import "MineCollectionViewCell.h"
#import "MineCollectionReusableView.h"

#import "ShoppingViewController.h"
//#import "FavoriteViewController.h"
#import "ProduceViewController.h"
//#import "SetSystemViewController.h"

@implementation MineView


-(instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    if (self) {
        [self createCollectionView];
    }
    return self;
}


-(void)createCollectionView{
    
    self.flayout = [[UICollectionViewFlowLayout alloc] init];
    self.flayout.itemSize = CGSizeMake(self.frame.size.width / 7 * 3, self.frame.size.height / 4);
    self.flayout.minimumLineSpacing = 10;
    self.flayout.minimumInteritemSpacing = 10;
    self.flayout.sectionInset = UIEdgeInsetsMake(15, 15, 50, 15);
    
    
    
    self.collectionView = [[UICollectionView alloc] initWithFrame:self.frame collectionViewLayout:self.flayout];
    [self addSubview:self.collectionView];
    self.collectionView.backgroundColor = [UIColor whiteColor];
    [self.collectionView release];
    
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    
    [self.collectionView registerClass:[MineCollectionViewCell class] forCellWithReuseIdentifier:@"mine"];
    
    self.flayout.headerReferenceSize = CGSizeMake( self.frame.size.width, self.frame.size.height / 100 * 35);
    [self.collectionView registerClass:[MineCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headerView"];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 4;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    MineCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"mine" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor colorWithWhite:0.1 alpha:0.1];
    NSMutableArray *array = [NSMutableArray arrayWithObjects:@"我的订单", @"我的收藏", @"我的介绍", @"系统设置",nil];
    cell.label.text = array[indexPath.row];
    
    
    if (indexPath.row == 0) {
        
        cell.image.image = [UIImage imageNamed:@"dd.png"];
        
    }
    else if(indexPath.row == 1){
        
        cell.image.image = [UIImage imageNamed:@"js.png"];
        
    }
    else if(indexPath.row == 2){
        
        cell.image.image = [UIImage imageNamed:@"sc.png"];
        
    }
    else {
        
        cell.image.image = [UIImage imageNamed:@"sz.png"];
        
    }
    
    
    
    return cell;
    
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    if(indexPath.row == 0){
        
        //      push到我的订单页面
        ShoppingViewController *shoppingVC = [[ShoppingViewController alloc] init];
        [self.VC.navigationController pushViewController:shoppingVC animated:YES];
        
    }
    
    
        //      block 到我的收藏页面
    else if (indexPath.row == 1) {
        
        
        self.blockFavorite();
        
    }
    
    
        //      模态到我的介绍页面
    else if (indexPath.row == 2) {
        
        
        ProduceViewController *produceVC = [[ProduceViewController alloc] init];
//        [self.VC.navigationController pushViewController:produceVC animated:YES];
        [produceVC setModalTransitionStyle:1];
        [self.VC presentViewController:produceVC animated:YES completion:^{
            
        }];
    }
    
    
        //      block 到系统设置页面
    else if (indexPath.row == 3) {
        
        
        self.Block();
        NSLog(@"oo");
        
    }
    
    
}



#pragma mark - 头视图
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    
    if (kind == UICollectionElementKindSectionHeader) {
        
        MineCollectionReusableView *reusableView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headerView" forIndexPath:indexPath];
        reusableView.backgroundColor = [UIColor colorWithWhite:0.8 alpha:0.9];
        reusableView.loginVC = self.loginVC;
        reusableView.registerVC = self.registerVC;
        return reusableView;
        
    }
    
    return nil;
}

@end
